package ding.service.Impl;

import ding.dao.BookDao;
import ding.dao.Impl.BookDaoImpl;
import ding.entity.Book;
import ding.service.BookService;
import ding.utils.Page;

import java.util.List;

public class BookServiceImpl implements BookService {

    BookDao bookDao = new BookDaoImpl();

    @Override
    public Page<Book> selectAll(String bookName, String author,int pageNum) {


        Page<Book> bookPage = new Page<>();
        bookPage.setTotalCount(bookDao.bookSize(bookName,author));
        bookPage.setPageNum(pageNum);

        List<Book> books = bookDao.selectAll(bookName, author, bookPage.getPageNum(), bookPage.getCount());
        bookPage.setDataList(books);


        return bookPage;
    }

    @Override
    public boolean saveBook(Book book) {
        int count = bookDao.add(book);
//        if (count>0){
//            return true;
//        }
//        return false;

        return count > 0 ? true : false;
    }

    @Override
    public Book detail(Integer id) {
        return bookDao.selectById(id);
    }

    @Override
    public boolean updateBook(Book book) {
        int count = bookDao.updateBook(book);

        return count > 0 ? true : false;
    }

    @Override
    public int delBook(Integer id) {
        return bookDao.delBook(id);
    }
}
